package cn.telling.product.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.telling.product.dao.ISupplyAreaDao;
import cn.telling.product.service.ISupplyAreaService;
import cn.telling.product.vo.AreaInfoVo;

/**
 * 
 * @ClassName: SupplyAreaServiceImpl 
 * @Description: 供应商销售区域业务服务接口的实现
 * @author 陈赟 
 * @date 2015年6月17日 下午2:47:50 
 *
 */
@Service("supplyAreaService")
public class SupplyAreaServiceImpl implements ISupplyAreaService {
    
    @Autowired
    @Qualifier("supplyAreaDao")
    private ISupplyAreaDao supplyAreaDao;

    @Override
    public List<AreaInfoVo> findSupplyAreaBySupplyId(String supplyId) {
    	 return supplyAreaDao.findSupplyAreaBySupplyId(supplyId);
    }

	@Override
	public List<AreaInfoVo> findSupplyAreaBySupplyIdForNoDirection(
			String supplyId) {
    	List<AreaInfoVo> listArea = new ArrayList<AreaInfoVo>();
    	List<AreaInfoVo> list=supplyAreaDao.findSupplyAreaBySupplyId(supplyId);
    	if(list!=null&&list.size()==1){
    		AreaInfoVo vo=list.get(0);
    		String areaId=vo.getAreaId().toString();
    		//销售区域是全国的情况
    		if("2".equals(areaId)&&"1".equals(vo.getAreaLevel().toString())){
    			listArea=supplyAreaDao.findSupplyAreaByAreaId(areaId);
    		}else{
    			listArea=list;
    		}
    	}else if(list!=null&&list.size()>1){
    		listArea=list;
    	}
        return listArea;
    }

}
